package com.help10000.rms.mvp.presenter

import com.amir.common.api.CustomObserver
import com.amir.common.beans.ApplyInitEntityWrapper
import com.amir.common.beans.BaseResult
import com.amir.common.mvp.model.Model
import com.amir.common.mvp.presenter.BasePresenter
import com.amir.common.utils.Constant
import com.amir.common.utils.SPUtils
import com.help10000.rms.mvp.view.ApplyWorkView

class ApplyWorkPresenter(view: ApplyWorkView) : BasePresenter<ApplyWorkView>(view) {

    /**
     * 初始化入职信息
     */
    fun applyInfoInit(cmpyCode: String?) {
        val accessToken = SPUtils.getString(Constant.AccessToken)
        val applyInit = Model.getServer().applyWorkInit(accessToken, cmpyCode)
        Model.getObservable(applyInit, object : CustomObserver<ApplyInitEntityWrapper>(mvpView) {

            override fun success(t: ApplyInitEntityWrapper) {
                mvpView?.initInfoSuccess(t.data)
            }
        })
    }

    /**
     * 提交入职信息
     */
    fun submitApplyInfo(map: Map<String, String>) {
        val accessToken = SPUtils.getString(Constant.AccessToken)
        val applyInit = Model.getServer().submitApply(accessToken, map)
        Model.getObservable(applyInit, object : CustomObserver<BaseResult>(mvpView) {

            override fun success(t: BaseResult) {
                mvpView?.submitSuccess()
            }
        })
    }
}